﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMSSoft.Lib.Interfaces;
using WMSSoft.Lib.Basic;

namespace WMSSoft.WinKStart.DataSource
{
    public class RegisterDataSourcesOptions : ISourceElementOptions
    {
        Dictionary<string, Dictionary<string, OptionInfo>> m_AssemblyElements = new Dictionary<string, Dictionary<string, OptionInfo>>();

        public RegisterDataSourcesOptions()
        {
            try
            {
                //register all Options for DataSources in this Assembly
                m_AssemblyElements.Add("WMSSoft.WinKStart.DataSource.FavoriteDataSource", new Dictionary<string, OptionInfo>());
                m_AssemblyElements.Add("WMSSoft.WinKStart.DataSource.RecentDataSource", new Dictionary<string, OptionInfo>());
                m_AssemblyElements.Add("WMSSoft.WinKStart.DataSource.StartmenuDataSource", new Dictionary<string, OptionInfo>());
                List<KeyValueAssignment> oYesNoValues = new List<KeyValueAssignment>();
                oYesNoValues.Add(new KeyValueAssignment("true", LanguageStrings.GetText("Yes")));
                oYesNoValues.Add(new KeyValueAssignment("false", LanguageStrings.GetText("No")));
                m_AssemblyElements["WMSSoft.WinKStart.DataSource.StartmenuDataSource"].Add("ShowAllUserItems", new OptionInfo(oYesNoValues, "true", "Show All User Items"));
                m_AssemblyElements["WMSSoft.WinKStart.DataSource.StartmenuDataSource"].Add("ShowAdministrativeTools", new OptionInfo(oYesNoValues, "false","Show Administrative Tools"));
                m_AssemblyElements.Add("WMSSoft.WinKStart.DataSource.SystemControlDataSource", new Dictionary<string, OptionInfo>());
                m_AssemblyElements["WMSSoft.WinKStart.DataSource.SystemControlDataSource"].Add("ShowAdministrativeTools", new OptionInfo(oYesNoValues, "false", "Show Administrative Tools"));
                m_AssemblyElements["WMSSoft.WinKStart.DataSource.SystemControlDataSource"].Add("ShowWinKStartItems", new OptionInfo(oYesNoValues, "true", "Show WinKStart Control Items"));
                m_AssemblyElements.Add("WMSSoft.WinKStart.DataSource.UserDataSource", new Dictionary<string, OptionInfo>());
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to Register Class Options!", Ex);
            }
        }

        public List<string> GetClassOptions(string Classname)
        {
            try
            {
                //implements code to retrieve a List with Option Keys
                if (m_AssemblyElements.ContainsKey(Classname) == true)
                {
                    Dictionary<string, OptionInfo>.KeyCollection KeyCollection = m_AssemblyElements[Classname].Keys;
                    return KeyCollection.ToList();
                }
                else
                    return null;
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to read Options for given Class '" + Classname + "'!", Ex);
            }
        }

        public OptionInfo GetClassOptionInfo(string Classname, string Optionname)
        {
            try
            {
                //TODO: implements Code to Retrieve the Details for asked Option
                if (m_AssemblyElements.ContainsKey(Classname) && m_AssemblyElements[Classname].ContainsKey(Optionname))
                {
                    return m_AssemblyElements[Classname][Optionname];
                }
                else
                    return null;
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to read Informations for Option '" + Optionname + "' in Class '" + Classname + "'!", Ex);
            }
        }
    }
}
